using System;
using BitMango.Diagnostics;
using UnityEngine;

namespace BitMango
{
	public static class DailyReward
	{
		public static bool IsRewardDay()
		{
			DateTime dateTime = default(DateTime);
			if (!DateTime.TryParse(PlayerPrefs.GetString("BitMangoDailyRewardDateTime"), out dateTime))
			{
				return true;
			}
			DateTime t = dateTime.AddDays(1.0);
			if (DailyReward.timeType == DailyReward.TIME_TYPE.HOUR_24)
			{
				return t < DateTime.Now;
			}
			return !dateTime.ToString("yyyy-MM-dd").Equals(DateTime.Now.ToString("yyyy-MM-dd"));
		}

		public static void ResetRewardDays()
		{
			for (int i = 1; i <= DailyReward.limit; i++)
			{
				PlayerPrefs.SetInt("BitMangoDailyReward" + i.ToString(), 0);
				PlayerPrefs.Save();
			}
		}

		public static bool HasRecivedReward(int rewardDay)
		{
			return PlayerPrefs.GetInt("BitMangoDailyReward" + rewardDay.ToString(), 0) > 0;
		}

		public static void MarkTodayReward()
		{
			PlayerPrefs.SetInt("BitMangoDailyReward" + DailyReward.GetRewardDay().ToString(), 1);
			PlayerPrefs.SetString("BitMangoDailyRewardDateTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
			PlayerPrefs.Save();
		}

		public static int GetRewardDay()
		{
			bool flag = DailyReward.IsRewardDay();
			Debugger.Assert(flag, "DailyReward.GetRewardDay : IsRewardDay false");
			int result;
			if (DailyReward.isProgressive)
			{
				result = DailyReward.GetProgressiveTypeRewardDay();
			}
			else
			{
				result = DailyReward.GetNotProgressiveTypeRewardDay();
			}
			return result;
		}

		private static int GetProgressiveTypeRewardDay()
		{
			int num = -1;
			for (int i = 1; i <= DailyReward.limit; i++)
			{
				if (PlayerPrefs.GetInt("BitMangoDailyReward" + i.ToString(), 0) == 0)
				{
					num = i;
					break;
				}
			}
			if (num == -1 && DailyReward.isRepeatDailyReward)
			{
				num = 1;
				DailyReward.ResetRewardDays();
			}
			return num;
		}

		private static int GetNotProgressiveTypeRewardDay()
		{
			int num = -1;
			DateTime d = default(DateTime);
			DateTime now = DateTime.Now;
			if (!DateTime.TryParse(PlayerPrefs.GetString("BitMangoDailyRewardDateTime"), out d))
			{
				num = 1;
			}
			else
			{
				for (int i = 1; i <= DailyReward.limit; i++)
				{
					int @int = PlayerPrefs.GetInt("BitMangoDailyReward" + i.ToString(), 0);
					if (@int > 0)
					{
						num = i;
					}
				}
				num += (now - d).Days;
				if (num > DailyReward.limit)
				{
					if (DailyReward.isRepeatDailyReward)
					{
						num = 1;
						DailyReward.ResetRewardDays();
					}
					else
					{
						num = -1;
					}
				}
			}
			return num;
		}

		public static bool isRepeatDailyReward;

		public static bool isProgressive;

		public static DailyReward.TIME_TYPE timeType;

		public static int limit = 7;

		public enum TIME_TYPE
		{
			HOUR_24,
			DAY_1
		}
	}
}
